﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using SKIT.FlurlHttpClient.Wechat.Api;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 微信接口
    /// </summary>
    [Route("api/wechat")]
    [ApiController]
    public class WeChatController : ControllerBase
    {
        /// <summary>
        /// 微信服务
        /// </summary>
        private readonly IWeChatService _weChatService;
        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="weChatService"></param>
        public WeChatController(IWeChatService weChatService) { _weChatService = weChatService; }

        /// <summary>
        /// 恩睦照护小程序登录
        /// </summary>
        /// <param name="js_code">通过 wx.login 接口获得临时登录凭证</param>
        /// <returns></returns>
        [HttpPost("zhao-hu-applet/login")]
        public async Task<Result<WeChatZhaohuAppletLoginDto>> WeChatZhaohuAppletLogin([FromForm][Required] string js_code)
        {
            return await _weChatService.WeChatZhaohuAppletLogin(js_code);
        }

        /// <summary>
        /// 恩睦照护小程序注册并登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("zhao-hu-applet/register")]
        public async Task<Result<WeChatZhaohuAppletLoginDto>> WeChatZhaohuAppletRegister(WeChatZhaohuAppletRegisterInput input)
        {
            return await _weChatService.WeChatZhaohuAppletRegister(input);
        }
    }
}
